package com.gibbs.audio.webrtc;

public class NsxContext {
    private final NoiseSuppressorUtils proxy;
    private final long nativeContext;

    public NsxContext() {
        proxy = new NoiseSuppressorUtils();
        nativeContext = proxy.nsxCreate();
    }

    /**
     * 初始化
     *
     * @param sampleRate 采样率
     * @return 0成功，-1失败
     */
    public int init(int sampleRate) {
        return proxy.nsxInit(nativeContext, sampleRate);
    }

    /**
     * 设置降噪级别，0~3，越大效果越明显
     *
     * @param level 0~3
     * @return 0成功，-1失败
     */
    public int setLevel(int level) {
        return proxy.nsxSetPolicy(nativeContext, level);
    }

    /**
     * 降噪处理，每次10ms，只支持8/16/32K
     *
     * @param inFrame  处理前数据
     * @param outFrame 处理后数据
     * @return 0成功，-1失败
     */
    public int process(short[] inFrame, short[] outFrame) {
        return proxy.nsxProcess(nativeContext, inFrame, 1, outFrame);
    }

    public int release() {
        return proxy.nsxFree(nativeContext);
    }
}
